package com.lc.railway.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.railway.R;
import com.lc.railway.http.glide.GlideApp;
import com.lc.railway.http.request.ApiProductHonorApi;
import com.lc.railway.http.response.ApiProductHonorBean;
import com.lc.railway.ui.dialog.FieldsDialog;
import com.lc.widget.layout.SettingBar;

import org.jetbrains.annotations.NotNull;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class HonorListActivity extends WaterActivity {
    @BindView(R.id.title_bar_top)
    TitleBar titleBarTop;
    @BindView(R.id.sb_honor)
    SettingBar sbHonor;
    @BindView(R.id.rv_honor)
    RecyclerView rvHonor;
    @BindView(R.id.sb_jiangli)
    SettingBar sbJiangli;
    @BindView(R.id.rv_jiangli)
    RecyclerView rvJiangli;
    @BindView(R.id.sb_gonggao)
    SettingBar sbGonggao;
    @BindView(R.id.rv_gonggao)
    RecyclerView rvGonggao;
    @BindView(R.id.sb_shiji)
    SettingBar sbShiji;
    @BindView(R.id.rv_shiji)
    RecyclerView rvShiji;
    @BindView(R.id.sb_jueding)
    SettingBar sbJueding;
    @BindView(R.id.rv_jueding)
    RecyclerView rvJueding;
    private BaseQuickAdapter<ApiProductHonorBean.DataBean.RongyuBean, BaseViewHolder> honoradapter;
    private BaseQuickAdapter<ApiProductHonorBean.DataBean.JiangliBean.ListsBean, BaseViewHolder> Jianglidapter;
    private BaseQuickAdapter<ApiProductHonorBean.DataBean.GongshiBean.ListsBean, BaseViewHolder> Gonggaodapter;
    private BaseQuickAdapter<ApiProductHonorBean.DataBean.DianxingBean.ListsBean, BaseViewHolder> shijiadapter;
    private BaseQuickAdapter<ApiProductHonorBean.DataBean.XuexiBean.ListsBean, BaseViewHolder> Juedingadapter;
    private String jiangliId;
    private String dianxingId;
    private String gongshiId;
    private String xuexiId;


    @Override
    protected int getLayoutId() {
        return R.layout.honorlist_activity;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        titleBarTop.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) {
                finish();
            }

            @Override
            public void onTitleClick(View v) {

            }

            @Override
            public void onRightClick(View v) {
                FieldsDialog dialog=new FieldsDialog(getContext(),HonorListActivity.this,"荣誉榜");
                dialog.show();
            }
        });
        honoradapter=new BaseQuickAdapter<ApiProductHonorBean.DataBean.RongyuBean, BaseViewHolder>(R.layout.item_honor) {
            @Override
            protected void convert(@NotNull BaseViewHolder holder, ApiProductHonorBean.DataBean.RongyuBean s) {
                GlideApp.with(getContext()).load(s.getPicurl()).error(R.drawable.image11).into(((ImageView) holder.getView(R.id.img_logo)));
                holder.setText(R.id.tv_title, s.getTitle());
            }
        };
        rvHonor.setAdapter(honoradapter);
        Jianglidapter=new BaseQuickAdapter<ApiProductHonorBean.DataBean.JiangliBean.ListsBean, BaseViewHolder>(R.layout.item_test) {
            @Override
            protected void convert(@NotNull BaseViewHolder holder, ApiProductHonorBean.DataBean.JiangliBean.ListsBean jiangliBean) {
                holder.setText(R.id.tv_title, jiangliBean.getTitle());
                holder.setText(R.id.tv_date,jiangliBean.getCreate_time());
            }
        };

        rvJiangli.setAdapter(Jianglidapter);
        Jianglidapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull @NotNull BaseQuickAdapter<?, ?> adapter, @NonNull @NotNull View view, int position) {
                startActivity(new Intent(getContext(),NewsDeatailsActivity.class).putExtra("id",Jianglidapter.getData().get(position).getId()+"").putExtra("title",Jianglidapter.getData().get(position).getTitle()+"").putExtra("content",Jianglidapter.getData().get(position).getTitle()).putExtra("picurl","").putExtra("time",Jianglidapter.getData().get(position).getCreate_time()));
            }
        });
        shijiadapter=new BaseQuickAdapter<ApiProductHonorBean.DataBean.DianxingBean.ListsBean, BaseViewHolder>(R.layout.item_test) {
            @Override
            protected void convert(@NotNull BaseViewHolder holder, ApiProductHonorBean.DataBean.DianxingBean.ListsBean jiangliBean) {
                holder.setText(R.id.tv_title, jiangliBean.getTitle());
                holder.setText(R.id.tv_date,jiangliBean.getCreate_time());
            }
        };
        rvShiji.setAdapter(shijiadapter);
        shijiadapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull @NotNull BaseQuickAdapter<?, ?> adapter, @NonNull @NotNull View view, int position) {
                startActivity(new Intent(getContext(),NewsDeatailsActivity.class).putExtra("id",shijiadapter.getData().get(position).getId()+"").putExtra("title",shijiadapter.getData().get(position).getTitle()+"").putExtra("content",shijiadapter.getData().get(position).getTitle()).putExtra("picurl","").putExtra("time",shijiadapter.getData().get(position).getCreate_time()));

            }
        });
        Juedingadapter=new BaseQuickAdapter<ApiProductHonorBean.DataBean.XuexiBean.ListsBean, BaseViewHolder>(R.layout.item_test) {
            @Override
            protected void convert(@NotNull BaseViewHolder holder, ApiProductHonorBean.DataBean.XuexiBean.ListsBean jiangliBean) {
                holder.setText(R.id.tv_title, jiangliBean.getTitle());
                holder.setText(R.id.tv_date,jiangliBean.getCreate_time());
            }
        };
        rvJueding.setAdapter(Juedingadapter);
        Juedingadapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull @NotNull BaseQuickAdapter<?, ?> adapter, @NonNull @NotNull View view, int position) {

                startActivity(new Intent(getContext(),NewsDeatailsActivity.class).putExtra("id",Juedingadapter.getData().get(position).getId()+"").putExtra("title",Juedingadapter.getData().get(position).getTitle()+"").putExtra("content",Juedingadapter.getData().get(position).getTitle()).putExtra("picurl","").putExtra("time",Juedingadapter.getData().get(position).getCreate_time()));

            }
        });
        Gonggaodapter=new BaseQuickAdapter<ApiProductHonorBean.DataBean.GongshiBean.ListsBean, BaseViewHolder>(R.layout.item_test) {
            @Override
            protected void convert(@NotNull BaseViewHolder holder, ApiProductHonorBean.DataBean.GongshiBean.ListsBean jiangliBean) {
                holder.setText(R.id.tv_title, jiangliBean.getTitle());
                holder.setText(R.id.tv_date,jiangliBean.getCreate_time());
            }
        };
        rvGonggao.setAdapter(Gonggaodapter);
        Gonggaodapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull @NotNull BaseQuickAdapter<?, ?> adapter, @NonNull @NotNull View view, int position) {

                startActivity(new Intent(getContext(),NewsDeatailsActivity.class).putExtra("id",Gonggaodapter.getData().get(position).getId()+"").putExtra("title",Gonggaodapter.getData().get(position).getTitle()+"").putExtra("content",Gonggaodapter.getData().get(position).getTitle()).putExtra("picurl","").putExtra("time",Gonggaodapter.getData().get(position).getCreate_time()));

            }
        });
        api_product_honor();
    }

    private void api_product_honor() {

        EasyHttp.post(this)
                .api(new ApiProductHonorApi())
                .request(new HttpCallback<ApiProductHonorBean>(this) {
                    @Override
                    public void onSucceed(ApiProductHonorBean data) {

                        if (data.getError_code() == 200) {
//
                            honoradapter.setNewData(data.getData().getRongyu());
                            jiangliId = data.getData().getJiangli().getId()+"";

                            Jianglidapter.setNewData(data.getData().getJiangli().getLists());
                            dianxingId = data.getData().getDianxing().getId()+"";
                            shijiadapter.setNewData(data.getData().getDianxing().getLists());
                            gongshiId = data.getData().getGongshi().getId()+"";
                            Gonggaodapter.setNewData(data.getData().getGongshi().getLists());
                            xuexiId = data.getData().getXuexi().getId()+"";
                            Juedingadapter.setNewData(data.getData().getXuexi().getLists());

                        }
                    }
                });
    }



    @OnClick({R.id.sb_honor, R.id.sb_jiangli, R.id.sb_gonggao, R.id.sb_shiji, R.id.sb_jueding})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.sb_honor:
                break;
            case R.id.sb_jiangli:
                startActivity(new Intent(getContext(),NewsSecondaryActivity.class).putExtra("id",jiangliId).putExtra("title","奖励决定"));
                break;
            case R.id.sb_gonggao:
                startActivity(new Intent(getContext(),NewsSecondaryActivity.class).putExtra("id",gongshiId).putExtra("title","公示公告"));
                break;
            case R.id.sb_shiji:
                startActivity(new Intent(getContext(),NewsSecondaryActivity.class).putExtra("id",dianxingId).putExtra("title","典型事迹"));
                break;
            case R.id.sb_jueding:
                startActivity(new Intent(getContext(),NewsSecondaryActivity.class).putExtra("id",xuexiId).putExtra("title","学习决定"));
                break;
        }
    }
}
